<%@page import="com.xnx3.j2ee.Global"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>  
<%@ taglib uri="http://www.xnx3.com/java_xnx3/xnx3_tld" prefix="x" %>
<jsp:include page="/wm/common/head.jsp">
	<jsp:param name="title" value="列表"/>
</jsp:include>
<script src="/<%=Global.CACHE_FILE %>Qishou_state.js"></script>
<jsp:include page="/wm/common/list/formSearch_formStart.jsp" ></jsp:include>
	<jsp:include page="/wm/common/list/formSearch_input.jsp">
		<jsp:param name="iw_label" value="电话"/>
		<jsp:param name="iw_name" value="phone"/>
	</jsp:include>
	<jsp:include page="/wm/common/list/formSearch_input.jsp">
		<jsp:param name="iw_label" value="工作状态" />
		<jsp:param name="iw_name" value="state" />
		<jsp:param name="iw_type" value="select" />
	</jsp:include>
	
    <input class="layui-btn iw_list_search_submit" type="submit" value="搜索" />
    <a class="layui-btn" onclick="getChengdanExecl();">导出excel</a>
	<a href="javascript:editItem(0,'');" class="layui-btn">添加骑手</a>
</form>
<div class="tabox" style="padding:0 20px;min-width: 1200px;">
<table class="layui-table iw_table" style="min-width: 1200px;">
  <thead>
    <tr>
    	<th style="width:100px; text-align:center">姓名</th>
        <th style="width:150px; text-align:center">骑手电话</th>
        <th style="width:150px; text-align:center">注册时间</th> 
        <th style="width:100px; text-align:center">服务次数</th>
        <th style="width:150px; text-align:center">工作状态</th>
        <th style="width:100px; text-align:center">操作</th>
    </tr> 
  </thead>
  <tbody>
  	<c:forEach items="${list}" var="item">
  		<tr>
  		  <td>${item.name}</td>
          <td><x:substring maxLength="25" text="${item.phone }"></x:substring> </td>
          <td><x:time linuxTime="${item.addtime }" format="yyyy-MM-dd HH:mm"></x:time></td>
          <td>${item.allServiceNumb}</td>
          <td><script type="text/javascript">document.write(state[${item.state}]);</script>
          <c:choose>
                   <c:when test="${item.state == 1}">
                        <botton class="layui-btn layui-btn-sm" onclick="agreeItem(${item.id}, '${item.name }');" style="margin-left: 3px;">设为请假</botton>
                   </c:when>
                   <c:when test="${item.state == 0}">
                        <botton class="layui-btn layui-btn-sm" onclick="agreeItem(${item.id}, '${item.name }');" style="margin-left: 3px;">设为正常</botton>
                   </c:when>
		  </c:choose>
          </td>
          <td style="width: 100px;">
          		<botton class="layui-btn layui-btn-sm" onclick="editItem(${item.id}, '${item.name }');" style="margin-left: 3px;">修改</botton>
          		<botton class="layui-btn layui-btn-sm" onclick="deleteItem(${item.id}, '${item.name }');" style="margin-left: 3px;">删除</botton>
          </td>
      </tr>
    </c:forEach>
  </tbody>
</table>
</div>
<!-- 通用分页跳转 -->
<jsp:include page="/wm/common/page.jsp"></jsp:include>

<script type="text/javascript">
//根据id删除
function deleteItem(id,name){
	var dtp_confirm = layer.confirm('确定要删除骑手“'+name+'”？删除后不可恢复！', {
	  btn: ['删除','取消'] //按钮
	}, function(){
		layer.close(dtp_confirm);
		
		parent.msg.loading("删除中");    //显示“操作中”的等待提示
		$.post('delete.json?id='+id, function(data){
		    parent.msg.close();    //关闭“操作中”的等待提示
		    if(data.result == '1'){
		        parent.msg.success('操作成功');
		        window.location.reload();	//刷新当前页
		     }else if(data.result == '0'){
		         parent.msg.failure(data.info);
		     }else{
		         parent.msg.failure();
		     }
		});

	}, function(){
	});
}
//设置工作状态
function agreeItem(id){
	parent.iw.loading("修改中");    //显示“操作中”的等待提示
	$.post("/wangge/qishou/stateEdit.json?id="+id, function(data){
	    parent.iw.loadClose();    //关闭“操作中”的等待提示
	    if(data.result == '1'){
			parent.iw.msgSuccess('操作成功');
			location.reload();
	     }else if(data.result == '0'){
			iw.msgFailure(data.info);
	     }else{
			iw.msgFailure();
	     }
	});
}

//修改
function editItem(id, name){
	layer.open({
		type: 2, 
		title:id > 0? '修改骑手&nbsp;[&nbsp;'+name+'&nbsp;]&nbsp;':'添加骑手', 
		area: ['540px', '400px'],
		shadeClose: true, //开启遮罩关闭
		content: 'edit.do?id='+id
	});
}

/**
 * 对象转url参数
 * @param {*} data,对象
 * @param {*} isPrefix,是否自动加上"?"
 */
function queryParams(data = {}, isPrefix = true, arrayFormat = 'brackets') {
    let prefix = isPrefix ? '?' : ''
    let _result = []
    if (['indices', 'brackets', 'repeat', 'comma'].indexOf(arrayFormat) == -1) arrayFormat = 'brackets';
    for (let key in data) {
        let value = data[key]
        // 去掉为空的参数
        if (['', undefined, null].indexOf(value) >= 0) {
            continue;
        }
        // 如果值为数组，另行处理
        if (value.constructor === Array) {
            // e.g. {ids: [1, 2, 3]}
            switch (arrayFormat) {
                case 'indices':
                    // 结果: ids[0]=1&ids[1]=2&ids[2]=3
                    for (let i = 0; i < value.length; i++) {
                        _result.push(key + '[' + i + ']=' + value[i])
                    }
                    break;
                case 'brackets':
                    // 结果: ids[]=1&ids[]=2&ids[]=3
                    value.forEach(_value => {
                        _result.push(key + '[]=' + _value)
                    })
                    break;
                case 'repeat':
                    // 结果: ids=1&ids=2&ids=3
                    value.forEach(_value => {
                        _result.push(key + '=' + _value)
                    })
                    break;
                case 'comma':
                    // 结果: ids=1,2,3
                    let commaStr = "";
                    value.forEach(_value => {
                        commaStr += (commaStr ? "," : "") + _value;
                    })
                    _result.push(key + '=' + commaStr)
                    break;
                default:
                    value.forEach(_value => {
                        _result.push(key + '[]=' + _value)
                    })
            }
        } else {
            _result.push(key + '=' + value)
        }
    }
    return _result.length ? prefix + _result.join('&') : ''
}


//导出execl
function getChengdanExecl(){
	var data = wm.getJsonObjectByForm($('.toubu_xnx3_search_form'));
	 window.open('/wangge/outdoc/getQishouExecl.json' + queryParams(data)); 
} 
</script>

<jsp:include page="/wm/common/foot.jsp"></jsp:include>